/** 
 * 项目名:shiro 
 * 文件名:FormFilterLoginServlet.java 
 * 包名:com.spring.shiro.servlet 
 * 创建日期:2015年2月13日下午3:39:43 
 * 版权(c): ZTESOFT TECHNOLOGY CO.,LTD.Copyright 2012-2030.All rights reserved
 * 
 */

package com.spring.shiro.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;

@WebServlet(name = "formFilterLoginServlet", urlPatterns = "/formfilterlogin")  
public class FormFilterLoginServlet extends HttpServlet {

	private static final long serialVersionUID = 6595102999965651064L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

		String errorClassName = (String)req.getAttribute("shiroLoginFailure");  
		
        if(UnknownAccountException.class.getName().equals(errorClassName)) {  
            req.setAttribute("error", "用户名/密码错误");  
            
        } else if(IncorrectCredentialsException.class.getName().equals(errorClassName)) {  
            req.setAttribute("error", "用户名/密码错误"); 
            
        } else if(errorClassName != null) {  
            req.setAttribute("error", "未知错误：" + errorClassName);  
        }  
        req.getRequestDispatcher("/WEB-INF/views/formfilterlogin.jsp").forward(req, resp);  
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		
		this.doGet(req, resp);
	}
	
}
